package com.example.platformhimybodymanage.controller;

import java.util.List;

import org.json.JSONString;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.example.platformhimybodymanage.api.OrderApi;
import com.example.platformhimybodymanage.cache.RegionCache;
import com.example.platformhimybodymanage.mqrsend.Sender;
import com.example.platformsharedcommon.entity.order.MiaoshaGoods;
import com.example.platformsharedcommon.util.ResponseResult;
import com.google.gson.JsonObject;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "测试controller")
@RestController
public class TestController {
	@Autowired
	private OrderApi orderApi;
	@Autowired
	private Sender sender;

	@GetMapping("test")
	public String test() {

		return orderApi.test();
	}

	@ApiOperation("测试聚合调用底层服务")
	@GetMapping("listOrder")
	public ResponseResult listOrder() {
		try {
			ResponseResult listOrderRsult = orderApi.listOrder();
			List<MiaoshaGoods> pageList = listOrderRsult.getPageList(MiaoshaGoods.class);
			for (MiaoshaGoods miaoshaGoods : pageList) {
				sender.Fanout(miaoshaGoods);
			}
			return listOrderRsult;
		} catch (Exception e) {
			return ResponseResult.error(e.getMessage());
		}
	}

	@ApiOperation("测试初始化")
	@GetMapping("region/{id}")
	public ResponseResult region(@PathVariable("id") Integer id) {
		return ResponseResult.ok(RegionCache.getRegionName(id));
	}

	@GetMapping("regionList/{id}")
	public ResponseResult regionList(@PathVariable("id") Integer id) {
		return ResponseResult.ok(RegionCache.regionList(id));
	}
}
